package com.leyou.common.advice;

import com.leyou.common.exception.LyException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
@Slf4j
public class ControllerExceptionAdvice {

/*
* @ExceptionHandler(RuntimeException.class)异常处理器处理RuntimeExpection异常
* @Param e 捕获的异常
* 可能出现异常的地方-->自定义异常(状态码,信息)--->然后被ExceptionHandler捕获返回给页面
* */
    @ExceptionHandler(LyException.class)
    public ResponseEntity<String>handleLyException(LyException e){
    return ResponseEntity.status(e.getStatus()).body(e.getMessage());
    }
}
